<?php
use doumiaoduo\layer\LayerConfirmWidget;
use doumiaoduo\layer\LayerIframeWidget;
use common\components\helpers\Fun;

LayerConfirmWidget::widget();
LayerIframeWidget::widget();
?>
    <div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height" id="toolbar"
         data-shelve_url="<?= \common\components\helpers\Fun::url(['goodscourse/shelve']) ?>" data-role="<?= $role ?>">
        <div id="search-area" class="yx-bgf7f7f7 yx-radius5 zx-mg yx-function2 yx-pr0">
            <?= \yii\helpers\Html::beginForm(Fun::url(['goodscourse/index', 'type_id' => \Yii::$app->request->get('type_id')]), 'get', ['enctype' => 'multipart/form-data']) ?>
            <div style="float: left">
                <?= \common\components\helpers\Search::dropDownList('cate_name', null, $tree, ['label' => '商品类型', 'promote' => '请选择', 'encode' => false, 'class' => 'search diy_select_txt']) ?>
                <?= \common\components\helpers\Search::dropDownList('status', null, [null => '请选择', 0 => '未设置', 1 => '上架', 2 => '驳回', 3 => '审核中'], ['label' => '状态', 'promote' => '请选择', 'class' => 'search diy_select_txt']) ?>
                <?= \common\components\helpers\Search::textInput('goods_name', null, ['label' => '商品名称', 'class' => 'search yx-width150 zx-lh24 yx-ml6']); ?>
                <?= \common\components\helpers\Search::textInput('mechanic_name', null, ['label' => '机构别名', 'class' => 'search yx-input-text zx-width150 yx-ml6']); ?>
                <?= \common\components\helpers\Search::submitButton('搜索', ['id' => 'search-handle', 'class' => "yx-search yx-radius2"]); ?>
            </div>
            <div class="yx-clear"></div>
            <?= \yii\helpers\Html::endForm() ?>
        </div>
        <!--/*表*/-->
        <div class="docs-main zx-mg">
            <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check"
                   data-tablesaw-mode="swipe" data-tablesaw-minimap>
                <thead>
                <tr class="yx-bgd2f6ec">
                    <th><?= \Yii::t('zhtfrontend', 'ID'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '商品名称'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '分类名称'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '教学形式'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '课程名称'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '教师名称'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '教室'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '上课时间'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '机构'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '年龄段'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '库存'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '价格'); ?></th>
                    <?php if ($role == 'admin' || $role == 'finance') { ?>
                        <th><?= \Yii::t('zhtfrontend', '课时补贴'); ?></th>
                    <?php } ?>
                    <th><?= \Yii::t('zhtfrontend', '状态'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '审核意见'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '创建时间'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '修改时间'); ?></th>
                    <th><?= \Yii::t('zhtfrontend', '操作'); ?></th>
                </tr>
                </thead>
                <?php if ($data): ?>
                    <?php foreach ($data as $item): ?>
                        <tr data-id="<?= $item['id'] ?>">
                            <td><?= $item['id'] ?></td>
                            <td><?= $item['name'] ?></td>
                            <td><?= $item['cate_name'] ?></td>
                            <td><?= $item['teacher_form'] ?></td>
                            <td><?= $item['course_name'] ?></td>
                            <td><?= $item['teacher_name'] ?></td>
                            <td><?= $item['room_name'] ?></td>
                            <td><?= $item['class_time'] ?></td>
                            <td><?= $item['mechanic_name'] ?></td>
                            <td><?= $item['suitable_age'] ?></td>
                            <td><?= $item['store'] ?></td>
                            <td><?= $item['price'] ?></td>
                        <?php if ($role == 'admin' || $role == 'finance') { ?>
                            <td><?= $item['cost'] ?></td>
                        <?php } ?>
                            <td><?= $item['status'] ?></td>
                            <td><?= $item['auditing'] ?></td>
                            <td><?= $item['created_at'] ?></td>
                            <td><?= $item['updated_at'] ?></td>
                            <td><?= $item['operate'] ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </table>
            <div style="text-align: right"><?= common\components\widgets\GoPager::widget(['pagination' => $pages]) ?></div>
        </div>
    </div>

<?php

$js = <<<JS
    $(document).on('click','.shelve',function(){
      var _this = $(this);
      var tr = _this.parents('tr');
      var td = _this.parent();
      var id = _this.data('id');
      $.post($('#toolbar').data('shelve_url'), {id:id,type:'coures'},function(data){
          if(data.status == 0){
              layer.msg(data.content,{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
          }else {
              if(data.is_shelve == 1){
                  td.html("<span style='color:#0E4DAA;cursor: pointer' title='点击下架' class='shelve'>已上架</span>");
              }else{
                   td.html("<span style='color:#ff659a;cursor: pointer' title='点击上架' class='shelve'>下架</span>");
              }
          }
          
      });
  });

    $(document).on('click','#export-handle',function(){
        var param=new Object();
        param.searchData=getElementValueObject('search');
        var url = $(this).data('url');
        $.post(url,{_csrf:yii.getCsrfToken(),param:JSON.stringify(param)},function(data){

         });
    });

JS;
$this->registerJS($js);

?>